from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
from django.contrib.auth import models as auth_models
from coolblog import models
from coolblog import feeds
from coolblog import sitemaps

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

handler404 = 'coolblog.frontend.views.page_not_found'

feed_dict = {
    'latest': feeds.LatestArticles,
}

sitemap_dict = {
    'blog': sitemaps.BlogSitemap,
}

urlpatterns = patterns(
    '',
    url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
        {'feed_dict': feed_dict}),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
        {'sitemaps': sitemap_dict}),
    url(r'^robots\.txt$', 'coolblog.views.robots'),
    url(r'^admin/', include('coolblog.admin.urls')),
)

urlpatterns += patterns(
    '',
    url(r'^reg/login/$', 'django.contrib.auth.views.login',
        {'template_name': 'admin/login.html'}),
    url(r'^reg/logout/$', 'django.contrib.auth.views.logout_then_login'),
)

urlpatterns += patterns(
    'coolblog.frontend.views',
    url(r'^$', 'index'),
    url(r'^article/(\w+)/$', 'view_article'),
    url(r'^category/(\w+)/$', 'view_category'),
    url(r'^author/(\w+)/$', 'view_author'),
    url(r'^tag/(\w+)/$', 'view_tag'),
    url(r'^archive/(?P<year>\d{4})/(?P<month>(0[1-9]|1[0-2]))/$', 
        'view_archive'),
)

if settings.DEBUG:
    urlpatterns += patterns(
        '',
        url(r'^404/$', 'coolblog.frontend.views.page_not_found'),
        url(r'^500/$', 'django.views.generic.simple.direct_to_template', 
            {'template': '500.html'}),
    )
